package org.ztr.aiollama.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.ai.image.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/9/23 20:21
 * @Description: 图片模型控制类 -- 调用硅基流动大模型生成图片，修改pom文件，注释其他代码
 * @Version: 1.0
 */
@RestController
@RequestMapping("/ai/images")
public class ImageModelController {
    private static final Logger logger = LogManager.getLogger(ImageModelController.class);

    private final ImageModel imageModel;

    public ImageModelController(ImageModel imageModel) {
        this.imageModel = imageModel;
    }


    @GetMapping("/chat")
    public String generateImage(String input) {
        ImageOptions options = ImageOptionsBuilder.builder()
                .model("Kwai-Kolors/Kolors")
                .height(1024)
                .width(1024)
                .build();

        ImagePrompt imagePrompt = new ImagePrompt(input, options);

        ImageResponse call = imageModel.call(imagePrompt);

        String url = call.getResult().getOutput().getUrl();

        return url;
    }

}
